<?php
//require_once(dirname(__FILE__) . '/sess.php');
require_once('../../../../wp-config.php');
require_once('../../../../wp-admin/admin.php');

/**
 * The value of $HTTP_RAW_POST_DATA will look something
 * like this:
 * action=edit&id=5\r\n
 * This is the content of the
 * post.
 *
 * So break it in two using explode, and you have the
 * `directive` as the first element in the array, and
 * the actual post content in the second.
 *
 * Use parse_str to turn the first element into variables.
 */
$request = explode("\r\n", $HTTP_RAW_POST_DATA, 2);

/**
 * Because the parse_str() function can turn any word in a string
 * into a variable, lets make sure someone doesn't try to slip in
 * user_ID in an attempt to trick the plugin into thinking they are
 * someone they are not.
 */
define('ENP_USERID', $user_ID);
parse_str($request[0]);
unset($user_ID);
if (!user_can_edit_post(ENP_USERID, $id)) {
	die('<div id="ajaxerror">'.__('Du hast nicht gen&uuml;gend Rechte, diesen Artikel zu bearbeiten!', simpax).'</div>');
}
$user_ID = ENP_USERID;

	$buffer = urldecode($buffer);
	$title = urldecode($title);
	$tags = urldecode($tags);
	$content = $request[1];

	if(get_magic_quotes_gpc()) {
		$title = stripslashes($title);
		$tags = stripslashes($tags);
		$content = stripslashes($content);
	}
	
	$postArr = array();
	$postArr['ID'] = (int) $id;
	$postArr['post_content'] = $wpdb->escape($content);
	$postArr['post_title'] = $wpdb->escape($title);
	$postArr['post_category'] = $categories;
	wp_update_post($postArr);
	
	/**
	 * Check for Ultimate Tag Warrior
	 */
	if (class_exists('UltimateTagWarriorCore')) {
		$tags = $wpdb->escape($tags);
		$tags = explode(',',$tags);
		$nTags = array();
		if (!empty($tags)) {
			foreach ($tags as $tg) {
				$nTags[] = urldecode($tg);
			}
			$utw->SaveTags($id, $nTags);
		}
	} else if (function_exists('jkeywords_localLink')) {
		/**
		 * Check for Jerome's Keywords
		 */
		delete_post_meta($id, KEYWORDS_META);
		$post_keywords = explode(',', $tags);
		foreach($post_keywords as $keyword) {
			if ( !empty($keyword ) ) {
				if ( !empty($keyword_list) )
					$keyword_list .= ",";
				$keyword_list .= trim(urldecode($keyword));
			}
		}
		if (!empty($keyword_list) ) {
			add_post_meta($id, KEYWORDS_META, $keyword_list);
		}
	}


?>
